# 1、打开文件👉获取Python中的文件对象
import time

f = open('E:\\PythonBasicKnowledge\\07 文件操作\\poem.txt', 'r', encoding='UTF-8')
print(F'打开文件👉{type(f)}')

# 2、读取 - read() - 返回值是str类型
print('💴💴💴read()💴💴💴')
# print(F'读取十字节👇\n{f.read(10)}')
# content = f.read()
# print(F'读取全部👇\n{content}')
# print(type(content))  # <class 'str'>

# 3、读取 - readlines() - 返回值是list类型
print('💴💴💴readlines()💴💴💴')
# content = f.readlines()
# print(type(content))
# print(content)

# 4、读取 - readline() - 一次调用读取一行
print('💴💴💴readline()💴💴💴')
# line1 = f.readline()
# line2 = f.readline()
# line3 = f.readline()
# print(type(line1))
# print(line1)
# print(line2)
# print(line3)

# 5、读取 - 循环文件对象
print('💴💴💴循环文件对象💴💴💴')
# for line in f:
#     print(F'👉{line}')

# 6、关闭文件对象
# f.close()  # 关闭文件占用

# time.sleep(1000 * 120)

# 7、with open - 会自动调用close()
with open('E:\\PythonBasicKnowledge\\07 文件操作\\poem.txt', 'r', encoding='UTF-8') as f:
    for line in f:
        print(F'🍀{line}')
